#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>


int showpath(const char *path)
{
	printf("%s\n", path);
	return 0;
}

int scan_dir(const char *path, int (*callback)(const char *path))
{
	assert(!!path);
	assert(!!callback);
	struct DIR *dp;
	if(!(dp=opendir(path))){
		perror("opendir");
		assert(0);
	}
	struct dirent *entry;
	while(!!(entry=readdir(dp))){
		if(entry->d_name[0]=='.'){
			continue;
		}
		char buffer[1024];
		sprintf(buffer, "%s/%s", path, entry->d_name);
		switch(entry->d_type){
		case DT_REG:
			callback(buffer);
			break;
		case DT_DIR:
			scan_dir(buffer, callback);
			break;
		
		}
	}
	closedir(dp);

}

int main(int argc, char *argv[])
{
	scan_dir("/home/chenjie", showpath);
	printf("__ino_t:%d, __off_t:%d, unsigned int:%d", sizeof(__ino_t), sizeof(__off_t), sizeof(unsigned long));
	return 0;
}

